﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using middleware.dominio;
using middleware.dominio.negocio;

namespace middleware
{
    public partial class VentanaLogin : Form
    {
        public VentanaLogin()
        {
            InitializeComponent();
            //Escondo el mensaje de error
            lblError.Visible = false;
        }

        private void btnConfirmar_Click(object sender, EventArgs e)
        {
            Loguearse();
        }

        private void txtContrasenia_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((e.KeyChar == (char)(Keys.Enter)))
            {
                Loguearse();
            }
        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            Dispose();
        }

        private void Loguearse()
        {
            Usuario usuarioLogueado = BusinessFactory.getMiddleware().usuarioCorrecto(txtUsuario.Text, txtContrasenia.Text);

            if (usuarioLogueado != null)
            {
                lblError.Visible = false;
                Dispose();
            }
            else
            {
                lblError.Visible = true;
            }
        }
    }
}
